import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class BMPViewer extends JPanel {

	public static void main(String args[]) {

		JFrame frame = new JFrame("Image Label");
		BMP bmp = new BMP();
		String src = "C:/dev/workspace/xprs5/eclipse/workspace/jimage/test/dp_index_grap.bmp";

		BufferedImage img = null;
		InputStream in = null;
		try {
			in = new java.io.FileInputStream(src);
			bmp.read(in);
			
			img = bmp.createPalleteBufferedImage();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		frame.add("Center", new BMPViewer(img));
		frame.pack();
		frame.setVisible(true);
	}

	BufferedImage img;

	public BMPViewer(BufferedImage img) {
		this.img = img;
		this.setSize(new Dimension(800, 600));
	}

	public Dimension getPreferredSize() {
		return new Dimension(800, 600);
	}

	public void paint(Graphics g) {

		Dimension size = getSize();
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, size.width, size.height);
		
		g.drawImage(img, 0, 0, null);
	}
}